/**
 * @author:albert
 */

package com.bkbw.live.battle.business.skill;

import java.lang.reflect.Constructor;
import java.util.HashMap;

import com.bkbw.live.battle.business.skill.ability.ShootAbility;
import com.bkbw.live.battle.business.skill.ability.SlashAbility;

public class AbilityFactory {
	protected HashMap<String, Class> abilityLib = new HashMap<String, Class>();
	protected static AbilityFactory instance = new AbilityFactory();
	
	public static AbilityFactory getInstance()
	{
		return instance;
	}
	
	private AbilityFactory()
	{
		abilityLib.put("ShootAbility", ShootAbility.class);
		abilityLib.put("SlashAbility", SlashAbility.class);
	}
	
	public AbilityBase createAbility(String abilityClass, String abilityId, HashMap<String, Object> param)
	{
		AbilityBase ability;
		try {
			Class[] paramType = new Class[]{String.class, HashMap.class};
			//Constructor constructor = Class.forName(abilityClass).getConstructor(paramType);
			Constructor constructor = abilityLib.get(abilityClass).getConstructor(paramType);

			ability = (AbilityBase)constructor.newInstance(abilityId, param);
			return ability;
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
